package com.gxt.riaapp.client.mvc.model;
import com.extjs.gxt.ui.client.Style.HideMode;
import com.extjs.gxt.ui.client.data.BaseTreeModel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.gxt.riaapp.client.RiaApp;

/**
 * 좌측 메뉴의 TreeItem과 ListItem에 채워질 entity class
 * 
 * @author winkos1
 * 
 */
public class Entry extends BaseTreeModel {
	private String name;
	private String id;
	private boolean fill;
	private boolean closable = true;
	private HideMode hideMode = HideMode.DISPLAY;
	protected Entry() {
	}
	
	/**
	 * Constructor
	 * 
	 * @param name
	 * @param example
	 * @param image
	 */
	public Entry(String name, LayoutContainer example, String image) {
		this.name = name;
		set("name", name);
		set("image", image);
		set("example", example);
	}
	public Entry(String name, LayoutContainer example) {
		this.name = name;
		set("name", name);
		set("example", example);
	}
	public Entry(String name, String id) {
		this.name = name;
		set("name", name);
		set("id", id);
		this.id = id;
	}
	public Entry(String name, String id, LayoutContainer example) {
		this.name = name;
		set("name", name);
		set("id", id);
		this.id = id;
		set("program", example); // example를 program으로 변경하자.
	}

	public Entry(String name, LayoutContainer example, String image,
			boolean fill) {
		this(name, example, image);
		this.fill = fill;
	}

	public Entry(String name, LayoutContainer example, String image,
			boolean fill, boolean closable) {
		this(name, example, image, fill);
		this.closable = closable;
	}

	public Entry(String name, LayoutContainer example, String image,
			boolean fill, boolean closable, HideMode hideMode) {
		this(name, example, image, fill, closable);
		this.setHideMode(hideMode);
	}

	public LayoutContainer getProgram() {
		return (LayoutContainer) get("program");
	}
	
	public String getId() {
		return id;
	}
	
	public HideMode getHideMode() {
		return hideMode;
	}

	public String getName() {
		return (String) get("name");
	}

	public boolean isClosable() {
		return closable;
	}

	public boolean isFill() {
		return fill;
	}

	public void setFill(boolean fill) {
		this.fill = fill;
	}

	public void setHideMode(HideMode hideMode) {
		this.hideMode = hideMode;
	}

	public String toString() {
		return getName();
	}
	
	public String getSourceUrl() {
		Object o = (Object) get("program");
		String name = o.getClass().getName();

		name = name.substring(name.lastIndexOf("program.") + 9);
		name = "code/" + name + ".html";
		name = name.replaceFirst("\\.", "/");

		return name;
	}
}
